<template>
    <rx-layout>

        <div slot="center">
            <rx-fit :isheader="isheader">
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <rx-list-title :title="i18n('list.myConcerns','我的关注')"></rx-list-title>
                    <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan" v-if="isheader">
                    <span class="table-page-search-submitButtons">
                      <a-button type="primary" icon="search"
                                @click="search">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                      <a-button style="margin-left: 4px" @click="cancel">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                      <a @click="toggleAdvanced" style="margin-left: 8px">
                        {{ advanced ? i18n('list.putAwayBtn','收起') : i18n('list.expansionBtn','展开') }}
                        <a-icon :type="advanced ? 'up' : 'down'"/>
                      </a>
                    </span>
                            </a-col>
                            <template v-if="advanced">
                                <a-col :span="colSpan">
                                    <a-form-item :label="i18n('form.itemTitle','事项标题')">
                                        <a-input :placeholder="i18n('form.itemTitle','事项标题','input')"
                                                 v-model="queryParam['Q_t.SUBJECT__S_LK']"/>
                                    </a-form-item>
                                </a-col>
                                <a-col :span="colSpan">
                                    <a-form-item :label="i18n('form.billNo','单号')">
                                        <a-input :placeholder="i18n('form.billNo','单号','input')"
                                                 v-model="queryParam['Q_BILL_NO__S_EQ']"/>
                                    </a-form-item>
                                </a-col>
                                <a-col :span="colSpan">
                                    <a-form-item :label="i18n('list.createTime','创建时间') + i18n('list.from','从')">
                                        <a-date-picker
                                            style="width: 100%"
                                            :placeholder="i18n('list.createTime','创建时间','input')"
                                            v-model="queryParam['Q_t.CREATE_TIME__D_GE']"
                                            format="YYYY-MM-DD"
                                            @change="searchRangeDateChange($event,$event,{queryField:'Q_t.CREATE_TIME__D_GE'},'YYYY-MM-DD')"
                                        />
                                    </a-form-item>
                                </a-col>
                                <a-col :span="colSpan">
                                    <a-form-item :label="i18n('list.to','至')">
                                        <a-date-picker
                                            style="width: 100%"
                                            :placeholder="i18n('list.createTime','创建时间','input')"
                                            v-model="queryParam['Q_t.CREATE_TIME__D_LE']"
                                            format="YYYY-MM-DD"
                                            @change="searchRangeDateChange($event,$event,{queryField:'Q_t.CREATE_TIME__D_LE'},'YYYY-MM-DD')"
                                        />
                                    </a-form-item>
                                </a-col>
                                <a-col :span="colSpan" v-if="!curApp.appId">
                                    <a-form-item :label="$ti18('rxForm.appId', '应用')">
                                        <rx-search-app @change="appChange" v-model="searchApps">
                                        </rx-search-app>
                                    </a-form-item>
                                </a-col>
                            </template>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-bpm/bpm/core/bpmInst/getMyConcern"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10', '30', '40']"
                    id-field="pkId"
                    :loadDataOnstart="true"
                    @selectChange="onSelectChange"
                >
            <span slot="appId" slot-scope="{ text, record }">
                {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
            </span>
                    <span slot="billNo" slot-scope="{ text, record, index }">
                {{ record.billNo }}
            </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="canShow(record)" @click.stop="operatorInst(record)">{{i18n('list.editForm','编辑表单')}}</span>
            <span @click="instDetail(record)">{{$ti18('rxList.detailBtn','明细')}}</span>
          </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>


<script>
    import {AppBaseList, RxLayout, Util, RxFit, RxGrid} from '@lowcode/jpaas-common-lib'
    import RxCategoryTreeeditor from '@/components/redxun/rx-category-treeeditor'
    import FlowUtil from "../js/FlowUtil";
    import BpmInstFormOperat from "@/views/modules/bpm/core/BpmInstFormOperat";
    import {mapState} from 'vuex';
    import AppSearch from "@/views/modules/share/AppSearch";
    import RxSearchApp from "@/views/modules/share/rx-search-app";
    import SysAppApi from "@/api/system/core/sysApp";
    import {openUrl} from "@/utils/util";
    export default {
        name: 'my-concern',
        mixins: [AppBaseList, FlowUtil,AppSearch],
        components: {
            RxLayout,
            RxFit,
            RxGrid,
            RxCategoryTreeeditor,
            RxSearchApp
        },
        computed: {
            ...mapState({
                // 所属应用
                allApps: state => state.appSetting ? state.appSetting.allApps : {}
            }),
        },
        data() {
            return {
                selTreeId: '',
                // 表头
                columns: [
                    {
                        title: this.$ti18('rxList.index', '序号'),
                        type: 'indexColumn',
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'},
                        width: 40,
                    },

                    {
                        title: this.i18n('form.itemTitle', '事项标题'),
                        dataIndex: 'subject',
                        width: 240,
                        ellipsis: false,
                    },
                    {
                        title: this.i18n('form.billNo', '业务单号'),
                        dataIndex: 'billNo',
                        scopedSlots: {customRender: 'billNo'},
                        width: 180,
                        ellipsis: false,
                    },
                    {
                        title: this.i18n('list.createTime', '创建时间'),
                        dataIndex: 'createTime',
                        width: 120,
                    },
                    {
                        title: this.i18n('form.appId', '所属应用'),
                        dataIndex: 'appId',
                        width: 140,
                        sortField: 'APP_ID_',
                        scopedSlots: {customRender: 'appId'}
                    },
                    {
                        title: this.$ti18('rxList.action', '操作'),
                        dataIndex: 'action',
                        width: 80,
                        scopedSlots: {customRender: 'action'},
                    },
                ],
                statisticConfig: {
                    type: "static_bpm",
                    table: "BPM_INST t JOIN BPM_INST_CONCERN ic ON t.INST_ID_ = ic.INST_ID_",
                    field: "t.TREE_ID_",
                    whereConf: [{
                        name: "USER_ID_",
                        alias: "ic.USER_ID_",
                        type: "string",
                        dateFormat: "",
                        op: "=",
                        value: "curUserId",
                        valueType: "context"
                    }]
                }
            }
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "MyConcern", key);
            },
            canShow(record) {
                if (record.formType == 'custom') {
                    return false;
                }
                if (record.status != 'SUCCESS_END' &&
                    record.status != 'CANCEL' &&
                    record.status != 'ARCHIVED') {
                    return true;
                }
                return false;
            },
            searchRangeDateChange(date, dateString, e, format) {
                if (date.length == 2) {
                    this.queryParam[e.queryField] = date[0].format('YYYY-MM-DD');
                } else {
                    this.queryParam[e.queryField] = date.format(format);
                }
            },
            handSelect(curRow) {
                let selTreeId = curRow.treeId
                this.loadData({Q_TREE_ID__S_EQ: selTreeId})
            },
            instDetail(record) {
                this.openDetail(record.appId, record.instId);
            },
            search() {
                this.$refs.table.loadData()
            },
            cancel() {
                this.resetSearch()
            },
            closeSearchbar() {
                //关闭过滤弹窗；（点击X触发）
                this.fitSearch = false;
            },
            operatorInst(record) {
                let appId=record.appId;
                SysAppApi.get(appId).then(res=>{
                  let app=res.data;
                  let path=app.path;
                  let url=`${path}/${app.clientCode}/formOperate/${record.instId}?appId=${appId}`;
                  let title="【" + record.subject + '】' + this.i18n('operator.title', '编辑表单数据');
                  openUrl({url:url,title:title,curVm:this,max:true, destroy:(action,data)=>{}});
                })
            },
        },
    }
</script>
<style scoped>


</style>

